<template>
  <div class="app-container">
    <div v-if="isShow == '接头'">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="">
          <el-select
            filterable
            v-model="queryParams.railwayId"
            placeholder="线名"
            clearable
            style="width: 140px"
          >
            <el-option
              v-for="dict in railwayNamearr"
              :key="dict.railwayName"
              :label="dict.railwayName"
              :value="dict.railwayId"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="">
          <el-select
            filterable
            clearable
            style="width: 140px"
            v-model="queryParams.stationId"
            placeholder="车站名"
          >
            <el-option
              v-for="dict in stationNamearr"
              :label="dict.stationName"
              :value="dict.stationId"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="">
          <el-select
            filterable
            clearable
            style="width: 140px"
            v-model="queryParams.progressTypeId"
            placeholder="上下行"
          >
            <el-option
              v-for="dict in progressTypearr"
              :label="dict.progressType"
              :value="dict.progressTypeId"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="">
          <el-select
            filterable
            clearable
            style="width: 140px"
            v-model="queryParams.trackId"
            placeholder="股道名称"
          >
            <el-option
              v-for="dict in trackCodearr"
              :label="dict.trackCode"
              :value="dict.trackId"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="" class="formitemcla">
          <el-input
            v-model="queryParams.mileageNumber"
            type="number"
            placeholder="里程"
            clearable
            style="width: 140px"
            @keyup.enter.native="handleQuery"
          >
            <template #suffix> km </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery" style="width: 90px"
            >查询</el-button
          >
          <el-button @click="resetQuery" style="width: 90px">重置</el-button>
          <el-button type="primary" style="width: 90px" @click="handleExport"
            >导出</el-button
          >
          <el-button type="primary" @click="handleAdd" style="width: 90px"
            >新增</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        v-loading="loading"
        :data="connectorList"
        height="62vh"
        border
        @selection-change="selectiontab"
      >
        <el-table-column type="selection" label="全选" width="50" />
        <!-- <el-table-column label="单位id" prop="unitId" />
      <el-table-column label="线路id" prop="railwayId" /> -->
        <el-table-column label="区段" prop="zone" />
        <el-table-column label="道岔编号" prop="turnoutCode" />
        <el-table-column label="道岔型号" prop="turnoutModel" />
        <el-table-column label="左右开" prop="leftRightOpen" />
        <el-table-column label="上下行" prop="progressType" />
        <el-table-column label="线名" prop="railwayName" />
        <el-table-column label="里程" prop="mileage" />
        <el-table-column label="位置" prop="supplementaryDescription" />
        <el-table-column label="数量(对)" prop="number" />
        <el-table-column label="备注" prop="remark" />

        <!-- <el-table-column label="车站名" prop="stationName" /> -->
        <!-- <el-table-column label="股道名称" prop="trackCode" /> -->
        <!-- <el-table-column label="股别" prop="stockType" /> -->
        <!-- <el-table-column label="接头类型" prop="connectorType" /> -->
        <!-- 
      <el-table-column label="数量(对)" prop="number" />
      <el-table-column label="异型接头联接形式(属性维护id)" prop="specialJointConnectionId" />
      <el-table-column label="采用异型钢轨型号" prop="specialRailModel" />
      <el-table-column label="健康值" prop="healthIndex" />
      <el-table-column label="隐患等级" prop="hiddenDangerLevel" />
      <el-table-column label="设备使用频率" prop="equipmentUsageFrequency" />
      <el-table-column label="设备综合效率(OEE)" prop="oee" />
      <el-table-column label="平均无故障工作时间(MTBF)" prop="mtbf" />
      <el-table-column label="平均修复时间(MTTR)" prop="mttr" />
      <el-table-column label="工区" prop="workArea" />
      <el-table-column label="人员" prop="user" />
      <el-table-column label="备注" prop="remark" /> -->
        <el-table-column label="直接数据" min-width="110">
          <template #default="scope" class="buttontext">
            <el-button link type="primary" @click="handleUpdate(scope.row)"
              >参数</el-button
            >
            <el-button link type="primary" @click="meansFun(scope.row)"
              >资料</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="关联数据" min-width="210">
          <template #default="scope" class="buttontext">
            <el-button link type="primary" @click="resumeUpdate(scope.row)"
              >作业履历</el-button
            >
            <el-button link type="primary" @click="deviceProblem(scope.row)"
              >设备问题</el-button
            >
            <el-button link type="primary" @click="businessFinance(scope.row)"
              >业财</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="关联设备" min-width="60">
          <template #default="scope" class="buttontext">
            <el-button link type="primary" @click="fishplatefun(scope.row)"
              >鱼尾板</el-button
            >
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <!-- <el-button link type="primary" @click="handleUpdate(scope.row)">修改</el-button> -->
            <el-button link type="primary" @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-dialog
      draggable
      title="资料"
      v-model="meansopen"
      width="1300px"
      append-to-body
      @close="closefun"
    >
      <means :forma="formam" parentName="站内接头" v-if="meansopen"></means>
    </el-dialog>
    <fishplate
      ref="fishplateRef"
      :forma="forma"
      :className="isShow"
      v-if="isShow == '鱼尾板'"
      :childValuefun="childValue"
      v-bind="$attrs"
      v-on="$listeners"
    ></fishplate>
    <!-- 添加或修改正线轨道设备-接头信息对话框 -->
    <el-dialog
      :title="title"
      v-model="open"
      width="1250px"
      append-to-body
      draggable
    >
      <el-form
        ref="form"
        :model="forma"
        :rules="rules"
        label-width="100px"
        :inline="true"
      >
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">位置</span>
          <span class="rightx"></span>
        </div>
        <el-form-item label="单位名称" prop="unitId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.unitId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in unitNameobj"
              :label="dict.unitName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="线名" prop="railwayId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.railwayId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in railwayNameobj"
              :label="dict.railwayName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上下行" prop="progressTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.progressTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in progressTypeobj"
              :label="dict.progressType"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车站名" prop="stationId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.stationId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in stationNameobj"
              :label="dict.stationName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="股道名称" prop="trackId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.trackId"
            placeholder="请输入"
          >
            <el-option
              v-for="dict in trackListobj"
              :label="dict.trackCode"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="里程" prop="mileageNumber">
          <el-input
            style="width: 180px"
            v-model="forma.mileageNumber"
            placeholder="请输入里程"
          />
        </el-form-item>
        <el-form-item label="股别" prop="stockTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.stockTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="(item, index) in stockTypeobj"
              :key="index"
              :label="item.propertyName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="位置" prop="supplementaryDescription">
          <el-input
            style="width: 180px"
            v-model="forma.supplementaryDescription"
            placeholder="请输入位置"
          />
        </el-form-item>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">特性</span>
          <span class="rightx"></span>
        </div>
        <!-- <el-form-item label="接头类型" prop="connectorTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.connectorTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="(item, index) in connectorTypeobj"
              :key="index"
              :label="item.propertyName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="道岔编号" prop="turnoutCodeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.turnoutId"
            placeholder="请选择"
            @change="turnoutCodefun"
          >
            <el-option
              v-for="dict in turnoutList"
              :label="dict.turnoutCode"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="道岔型号" prop="turnoutModel">
          <el-input
            style="width: 180px"
            v-model="forma.turnoutModel"
            placeholder="请输入道岔型号"
            disabled
          />

          <!-- <el-select filterable clearable style="width: 180px" v-model="forma.turnoutModelId" placeholder="请选择">
            <el-option v-for="dict in turnoutModelobj" :label="dict.propertyName" :value="dict.id"></el-option>
          </el-select> -->
        </el-form-item>
        <el-form-item label="左右开" prop="leftRightOpen">
          <el-input
            style="width: 180px"
            v-model="forma.leftRightOpen"
            placeholder="请输入左右开"
            disabled
          />
          <!-- <el-select filterable clearable style="width: 180px" v-model="forma.leftRightOpen" placeholder="请选择">
            <el-option v-for="dict in leftRightOpenobj" :label="dict.propertyName" :value="dict.id"></el-option>
          </el-select> -->
        </el-form-item>
        <el-form-item label="数量(对)" prop="number">
          <el-input
            style="width: 180px"
            v-model="forma.number"
            type="number"
            placeholder="请输入数量(对)"
          />
        </el-form-item>
        <!-- <el-form-item label="异型接头联接形式" prop="specialJointConnectionId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.specialJointConnectionId"
            placeholder="请选择"
          >
            <el-option
              v-for="(item, index) in specialJointConnectionobj"
              :key="index"
              :label="item.propertyName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="采用异型钢轨型号" prop="specialRailModel">
          <el-input
            style="width: 180px"
            v-model="forma.specialRailModel"
            placeholder="请输入采用异型钢轨型号"
          />
        </el-form-item> -->
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">健康度</span>
          <span class="rightx"></span>
        </div>
        <el-form-item label="健康值" prop="healthIndex">
          <el-input
            style="width: 180px"
            v-model="forma.healthIndex"
            placeholder="请输入健康值"
          />
        </el-form-item>
        <el-form-item label="隐患等级" prop="hiddenDangerLevel">
          <el-input
            style="width: 180px"
            v-model="forma.hiddenDangerLevel"
            placeholder="请输入隐患等级"
          />
        </el-form-item>
        <el-form-item label="设备使用频率" prop="equipmentUsageFrequency">
          <el-input
            style="width: 180px"
            v-model="forma.equipmentUsageFrequency"
            placeholder="请输入设备使用频率"
          />
        </el-form-item>
        <el-form-item label="设备综合效率(OEE)" prop="oee">
          <el-input
            style="width: 180px"
            v-model="forma.oee"
            placeholder="请输入设备综合效率(OEE)"
          />
        </el-form-item>
        <el-form-item label="平均无故障工作时间(MTBF)" prop="mtbf">
          <el-input
            style="width: 180px"
            v-model="forma.mtbf"
            placeholder="请输入平均无故障工作时间(MTBF)"
          />
        </el-form-item>
        <el-form-item label="平均修复时间(MTTR)" prop="mttr">
          <el-input
            style="width: 180px"
            v-model="forma.mttr"
            placeholder="请输入平均修复时间(MTTR)"
          />
        </el-form-item>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">管理</span>
          <span class="rightx"></span>
        </div>
        <el-form-item label="区段" prop="zone">
          <el-input
            style="width: 180px"
            v-model="forma.zone"
            placeholder="请输入区段"
          />
        </el-form-item>
        <el-form-item label="工区" prop="workArea">
          <el-input
            style="width: 180px"
            v-model="forma.workArea"
            placeholder="请输入工区"
          />
        </el-form-item>
        <el-form-item label="人员" prop="user">
          <el-input
            style="width: 180px"
            v-model="forma.user"
            placeholder="请输入人员"
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="forma.remark"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 4 }"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="divflex" v-if="title == '接头信息修改'">
        <span class="leftx"></span>
        <span class="mainz">修改历史</span>
        <span class="rightx"></span>
      </div>
      <el-table
        v-if="title == '接头信息修改'"
        :data="historyList"
        height="20vh"
        border
      >
        <el-table-column
          label="序号"
          type="index"
          min-width="80"
        ></el-table-column>
        <el-table-column
          label="指标名"
          prop="property"
          min-width="80"
        ></el-table-column>
        <el-table-column label="变更前指标值" prop="oldValue" min-width="110">
        </el-table-column>
        <el-table-column label="变更后指标值" prop="newValue" min-width="80">
        </el-table-column>
        <el-table-column label="变更时间" prop="createTime" min-width="80">
        </el-table-column>
        <el-table-column label="操作用户名" prop="user" min-width="80">
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name="injoint">
import fishplate from "../offlineDevice/fishplate/index.vue";
import {
  insertManStationFacilityConnectorapi,
  selectManStationFacilityConnectorListapi,
  editManStationFacilityConnectorapi,
  deleteManStationFacilityConnectorByIdapi,
  selectManBasicRailwayListapi,
  selectManBasicUnitListapi,
  selectManBasicPropertyListapi,
  selectManBasicStationListapi,
  selectManStationFacilityTrackListapi,
  selectManStationFacilityTurnoutListapi,
  selectManRailEditRecordListapi,
  selectManBasicprogressTypeListapi,
} from "@/api/main/api.js";
import { useContent } from "@/mixin/index.js";
const {
  meansopen,
  meansFun,
  formam,
  closefun,
  resumeUpdate,
  deviceProblem,
  businessFinance,
} = useContent();
import means from "@/components/railmodle/means.vue";
defineExpose({ getList, AparentCount });
const emit = defineEmits(["parentCount", "clearnum"]);

import { reactive, ref, toRefs } from "vue";
const { proxy } = getCurrentInstance();
const router = useRouter();
const loading = ref(true);
const isShow = ref("接头");
const title = ref("接头信息新增");
const open = ref(false);
const data = reactive({
  // 基础数据-单位数据表格数据
  connectorList: [],
  // 查询参数
  queryParams: {
    pageNum: "1",
    pageSize: "10",
    railwayId: "",
    railwayName: "",
    mileageNumber: "",
    stationName: "",
    trackCode: "",
    stationId: "",
    trackId: "",
    progressType: "",
    progressTypeId: "",
  },
  railwayNameobj: [],
  unitNameobj: [],
  // 表单参数
  forma: {},
  // 表单校验
  rules: {
    unitId: [
      {
        required: true,
        message: "单位名称不能为空",
        trigger: ["blur", "change"],
      },
    ],
    railwayId: [
      {
        required: true,
        message: "线路名称不能为空",
        trigger: ["blur", "change"],
      },
    ],
    stationId: [
      {
        required: true,
        message: "车站名称不能为空",
        trigger: ["blur", "change"],
      },
    ],
    progressTypeId: [
      {
        required: true,
        message: "上下行不能为空",
        trigger: ["blur", "change"],
      },
    ],
    // trackId: [
    //   {
    //     required: true,
    //     message: "股道名称不能为空",
    //     trigger: ["blur", "change"],
    //   },
    // ],
    mileageNumber: [
      { required: true, message: "里程不能为空", trigger: ["blur", "change"] },
    ],
    // connectorTypeId: [
    //   {
    //     required: false,
    //     message: "接头类型不能为空",
    //     trigger: ["blur", "change"],
    //   },
    // ],
  },
  editobj: {},
  railwayNamearr: [],
  propertyList: [],
  brokenChainTypeobj: [],
  gaugeTypeobj: [],
  stockTypeobj: [],
  connectorTypeobj: [],
  specialJointConnectionobj: [],
  stationNamearr: [],
  trackCodearr: [],
  stationNameobj: [],
  trackListobj: [],
  turnoutModelobj: [],
  leftRightOpenobj: [],
  turnoutList: [],
  historyList: [],
  selecttabList: [],
  progressTypearr: [],
  progressTypeobj: [],
});
const {
  progressTypeobj,
  progressTypearr,
  selecttabList,
  historyList,
  turnoutList,
  leftRightOpenobj,
  turnoutModelobj,
  stationNameobj,
  trackListobj,
  stationNamearr,
  trackCodearr,
  stockTypeobj,
  connectorTypeobj,
  specialJointConnectionobj,
  gaugeTypeobj,
  brokenChainTypeobj,
  propertyList,
  railwayNamearr,
  queryParams,
  forma,
  rules,
  connectorList,
  unitNameobj,
  railwayNameobj,
  editobj,
} = toRefs(data);
/** 查询基础数据-行别数据列表 */
function getList8() {
  selectManBasicprogressTypeListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      progressTypeobj.value = res.data;
    }
  });
}
getList8();
//修改记录查询
function historyListfun() {
  selectManRailEditRecordListapi({ equipmentId: editobj.value.id }).then(
    (res) => {
      historyList.value = res.data;
    }
  );
}
function selectiontab(row) {
  selecttabList.value = row;
}
/** 导出按钮操作 */
function handleExport() {
  if (selecttabList.value.length == 0) {
    proxy.$modal.msgError("请选择设备");
    return;
  }
  const arrid = [];
  for (let i = 0; i < selecttabList.value.length; i++) {
    arrid.push(selecttabList.value[i].id);
  }
  proxy.download1(
    "facility-manage/stationFacilityConnector/exportExcel",
    arrid,
    `站内接头${new Date().getTime()}.xlsx`
  );
}
const pageNumparent = ref(undefined);
const pageSizeparent = ref(undefined);
const fishplateRef = ref(null);

//给关联设备传值
function AparentCount(pageNum, pageSize, type) {
  if (type == "鱼尾板") {
    fishplateRef.value.getList(pageNum, pageSize);
  }
}
/** 查询列表 */
function getList(pageNum, pageSize) {
  loading.value = true;
  if (pageNum != undefined || pageSize != undefined) {
    pageNumparent.value = pageNum;
    pageSizeparent.value = pageSize;
    queryParams.value.pageNum = pageNum == undefined ? 1 : pageNum;
    queryParams.value.pageSize = pageSize == undefined ? 10 : pageSize;
  } else {
    queryParams.value.pageNum =
      pageNumparent.value == undefined ? "1" : pageNumparent.value;
    queryParams.value.pageSize =
      pageSizeparent.value == undefined ? "10" : pageSizeparent.value;
  }
  selectManStationFacilityConnectorListapi(queryParams.value).then((res) => {
    if (res.code == 200) {
      connectorList.value = res.data;
      const xian = {};
      railwayNamearr.value = connectorList.value.reduce((next, item) => {
        xian[item.railwayName] == undefined
          ? (xian[item.railwayName] = true & next.push(item))
          : "";
        return next;
      }, []);
      const daoc = {};
      stationNamearr.value = connectorList.value.reduce((next, item) => {
        daoc[item.stationName] == undefined
          ? (daoc[item.stationName] = true & next.push(item))
          : "";
        return next;
      }, []);
      const gudaobh = {};
      trackCodearr.value = connectorList.value.reduce((next, item) => {
        gudaobh[item.trackCode] == undefined
          ? (gudaobh[item.trackCode] = true & next.push(item))
          : "";
        return next;
      }, []);
      const hang = {};
      progressTypearr.value = connectorList.value.reduce((next, item) => {
        hang[item.progressType] == undefined
          ? (hang[item.progressType] = true & next.push(item))
          : "";
        return next;
      }, []);
      loading.value = false;
      emit("parentCount", res.count);
    }
  });
}
getList();
//重置
function resetQuery() {
  queryParams.value = {
    railwayId: "",
    railwayName: "",
    mileageNumber: "",
    stationName: "",
    trackCode: "",
    stationId: "",
    trackId: "",
    progressType: "",
    progressTypeId: "",
  };
  getList();
}
/** 查询基础数据-单位数据列表 */
function getList1() {
  selectManBasicRailwayListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      railwayNameobj.value = res.data;
    }
  });
}
getList1();
/** 查询基础数据-线名数据列表 */
function getList2() {
  selectManBasicUnitListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      unitNameobj.value = res.data;
    }
  });
}
getList2();
/** 查询基础数据-车站数据列表 */
function getList3() {
  selectManBasicStationListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      stationNameobj.value = res.data;
    }
  });
}
getList3();
/** 查询基础数据-股道数据列表 */
function getList5() {
  selectManStationFacilityTrackListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      trackListobj.value = res.data;
    }
  });
}
getList5();
/** 查询基础数据-属性维护数据列表 */
function getList4() {
  selectManBasicPropertyListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      propertyList.value = res.data;
      stockTypeobj.value = [];
      connectorTypeobj.value = [];
      specialJointConnectionobj.value = [];
      turnoutModelobj.value = [];
      leftRightOpenobj.value = [];
      for (let i = 0; i < propertyList.value.length; i++) {
        if (propertyList.value[i].propertyType == "股别") {
          stockTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "接头类型") {
          connectorTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "异型接头联接形式") {
          specialJointConnectionobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "左右开") {
          leftRightOpenobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "道岔型号") {
          turnoutModelobj.value.push(propertyList.value[i]);
        }
      }
    }
  });
}
getList4();
/** 查询基础数据-道岔数据列表 */
function getList6() {
  selectManStationFacilityTurnoutListapi(queryParams.value).then((res) => {
    if (res.code == 200) {
      turnoutList.value = res.data;
    }
  });
}
getList6();
function turnoutCodefun() {
  for (let i = 0; i < turnoutList.value.length; i++) {
    if (forma.value.turnoutId == turnoutList.value[i].id) {
      forma.value.turnoutModel = turnoutList.value[i].turnoutModel;
      forma.value.leftRightOpen = turnoutList.value[i].leftRightOpen;
    }
  }
}
// 取消按钮
function cancel() {
  open.value = false;
}
/** 搜索按钮操作 */
function handleQuery() {
  getList();
}
function clear() {
  forma.value = {
    progressType: "",
    progressTypeId: "",
    railwayName: "",
    stockType: "",
    connectorType: "",
    specialJointConnection: "",
    unitName: "",
    unitId: "",
    railwayId: "",
    mileage: "",
    mileageNumber: "",
    stockTypeId: "",
    supplementaryDescription: "",
    connectorTypeId: "",
    number: "",
    specialJointConnectionId: "",
    specialRailModel: "",
    healthIndex: "",
    hiddenDangerLevel: "",
    equipmentUsageFrequency: "",
    oee: "",
    mtbf: "",
    mttr: "",
    zone: "",
    workArea: "",
    user: "",
    hasDelete: "",
    stationName: "",
    stationId: "",
    trackCode: "",
    trackId: "",
    turnoutModelId: "",
    turnoutModel: "",
    leftRightOpenId: "",
    leftRightOpen: "",
    turnoutCode: "",
    turnoutCodeId: "",
  };
}
/** 新增按钮操作 */
function handleAdd() {
  open.value = true;
  clear();
  title.value = "接头信息新增";
}
/** 修改按钮操作 */
function handleUpdate(row) {
  title.value = "接头信息修改";
  editobj.value = JSON.parse(JSON.stringify(row));
  forma.value = JSON.parse(JSON.stringify(row));
  historyListfun();
  open.value = true;
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["form"].validate((valid) => {
    if (valid) {
      if (forma.value.id != null) {
        const newforma = JSON.parse(JSON.stringify(forma.value));
        for (const key in editobj.value) {
          for (const keya in newforma) {
            if (
              key == keya &&
              editobj.value[key] == newforma[keya] &&
              key != "id"
            ) {
              Reflect.deleteProperty(newforma, keya);
            }
          }
        }

        if (
          newforma.mileageNumber != undefined &&
          newforma.mileageNumber != null
        ) {
          newforma.mileageNumber =
            Math.round(newforma.mileageNumber * 1000000) / 1000000;
        }
        if (Object.keys(newforma).length <= 1) {
          open.value = false;
        } else {
          editManStationFacilityConnectorapi(newforma).then((res) => {
            proxy.$modal.msgSuccess("修改成功");
            open.value = false;
            getList();
          });
        }
      } else {
        forma.value.mileageNumber =
          Math.round(forma.value.mileageNumber * 1000000) / 1000000;
        insertManStationFacilityConnectorapi(forma.value).then((res) => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
//鱼尾板
function fishplatefun(row) {
  forma.value = JSON.parse(JSON.stringify(row));
  isShow.value = "鱼尾板";
  emit("clearnum", 1, 10);
  // router.push({ path: "/offlineDevice/fishplate" });
}
function childValue() {
  isShow.value = "接头";
  getList(1, 10);
  emit("clearnum", 1, 10);
}
/** 删除按钮操作 */
function handleDelete(row) {
  proxy.$modal
    .confirm("是否确认删除")
    .then(function () {
      return deleteManStationFacilityConnectorByIdapi({ id: row.id });
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}
</script>
<style scoped lang="scss">
.el-form--inline .el-form-item.formitemcla {
  margin-right: 5px !important;
}
</style>
